package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.CommentBlack;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import com.zrwl.poscloud.xo.mapper.CommentBlackMapper;
import com.zrwl.poscloud.xo.service.CommentBlackService;
import com.zrwl.poscloud.xo.vo.CommentBlackVO;

import javax.annotation.Resource;

/**
 * 禁言记录管理 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-05-08
 */
@Service
public class CommentBlackServiceImpl extends SuperServiceImpl<CommentBlackMapper,CommentBlack> implements CommentBlackService {

    @Autowired
    private CommentBlackService commentBlackService;
    @Resource
    private CommentBlackMapper commentBlackMapper;

    @Override
    public IPage<CommentBlackVO> getPageList(CommentBlackVO commentBlackVO){
//       QueryWrapper<CommentBlack> queryWrapper = new QueryWrapper<>();
//       if (StringUtils.isNotEmpty(commentBlackVO.getKeyword()) && !StringUtils.isEmpty(commentBlackVO.getKeyword().trim())) {
//            queryWrapper.like("name", commentBlackVO.getKeyword().trim());
//       }
       Page<CommentBlack> page = new Page<>();
       page.setCurrent(commentBlackVO.getCurrentPage());
       page.setSize(commentBlackVO.getPageSize());
//       queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
//       queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
       IPage<CommentBlackVO> pageList = commentBlackMapper.getPageList(page, commentBlackVO);
       List<CommentBlackVO> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<CommentBlack> getAllList(CommentBlackVO commentBlackVO){
        QueryWrapper<CommentBlack> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<CommentBlack> list = commentBlackService.list(queryWrapper);
        return list;
}
    @Override
    public String add(CommentBlackVO commentBlackVO){
        CommentBlack entity = new CommentBlack();
        BeanUtils.copyProperties(commentBlackVO, entity, SysConf.STATUS);
        entity.insert();
        commentBlackVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(CommentBlackVO commentBlackVO){
        CommentBlack entity = commentBlackService.getById(commentBlackVO.getUid());
        BeanUtils.copyProperties(commentBlackVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(CommentBlackVO commentBlackVO){
        CommentBlack entity = commentBlackService.getById(commentBlackVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
